﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using AMS.UI.Controls;
using AMS.DataAccess.Trademark.Interfaces;
using AMS.DataAccess.Trademark.BO;
using AMS.ComponentModel;

namespace AMS.Trademark.Management.Components
{
    public partial class ucTaskDetail : BaseComponent, IDetailControl
    {
        public ucTaskDetail()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 
        /// </summary>
        public string Title
        {
            get { return string.Format("任务信息 - " + dataKey); }
        }
        /// <summary>
        /// 
        /// </summary>
        public string TaskIndex
        {
            get { return txtTaskIndex.Text.Trim(); }
        }

        private string dataKey;
        public object DataBind(string key)
        {
            dataKey = key;
            IRFTaskManager rftask = ObjectUtility.GetObject<IRFTaskManager>("RFTask");
            TaskCategoryInfo task = rftask.GetTask(key);
            DataBind(task);
            return task;
        }

        public void DataBind(TaskCategoryInfo task)
        {
            if (task != null)
            {
                txtAddDayInner.Value = task.iAddDay;
                txtAddDayOuter.Value = task.oAddDay;
                txtAddMonthInner.Value = task.iAddMonth;
                txtAddMonthOuter.Value = task.oAddMonth;
                txtTaskIndex.Text = task.TaskIndex;
                txtTaskName.Text = task.TaskName;
                cmbTaskType.Select(task.Type);
            }
        }

        internal void SetEditStatus()
        {
            SetEditable();
            txtTaskIndex.ReadOnly = true;
        }

        internal void SetNewStatus()
        {
            SetEditable();
        }

        internal bool CheckData()
        {
            if (txtTaskIndex.Text.Trim() == "")
            {
                Balloon.balloon("请输入任务编号", txtTaskIndex);
                return false;
            }
            if (txtTaskName.Text.Trim() == "")
            {
                Balloon.balloon("请输入任务名称", txtTaskName);
                return false;
            }
            if (cmbTaskType.SelectedIndex < 0)
            {
                Balloon.balloon("请选择类型", cmbTaskType);
                return false;
            }

            return true;
        }

        internal void UpdateTask(TaskCategoryInfo task)
        {
            task.TaskIndex = txtTaskIndex.Text.Trim();
            task.TaskName = txtTaskName.Text.Trim();
            task.Type = cmbTaskType.SelectedDictKey;
            task.iAddDay = txtAddDayInner.Value;
            task.iAddMonth = txtAddMonthInner.Value;
            task.oAddDay = txtAddDayOuter.Value;
            task.oAddMonth = txtAddMonthOuter.Value;
        }
    }
}
